package com.google.enterprise.mailmigration;

import com.google.gdata.util.AuthenticationException;

import java.io.IOException;

import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;

public class MigrationTester {
    private UserMigrator um;
    private static String oldUser;
    private static String oldPwd;
    private static String gooDomain;
    private static String gooUser;
    
    public static void main(String[] args) {
        UserMigrator userMigrator;
        XMLConfiguration config = null;

        try {
            config = new XMLConfiguration("usermigrationdata.xml");
            oldUser = config.getProperty("olduser").toString();
            oldPwd = config.getProperty("oldpwd").toString();
            gooDomain = config.getProperty("goodomain").toString();
            gooUser = config.getProperty("goouser").toString();
            
            System.out.println("Migrating " + oldUser + " to Google user " + gooUser);
            userMigrator = 
                    new UserMigrator(oldUser, oldPwd, gooDomain, gooUser);
            userMigrator.oldConnect();
            userMigrator.gooConnect();
            userMigrator.migrate();
            userMigrator.oldDisconnect();
        } catch (NoSuchProviderException e) {
            System.out.println("NoSuchProviderException caught. " + e.toString());
            e.printStackTrace();
        } catch (MessagingException e) {
            System.out.println("MessagingException caught. " + e.toString());
            e.printStackTrace();
        } catch (AuthenticationException e) {
            System.out.println("AuthenticationException caught. " + e.toString());
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("IOException caught. " + e.toString());
            e.printStackTrace();
        } catch (ConfigurationException e) {
            System.out.println("ConfigurationException caught. " + e.toString());
            e.printStackTrace();
        }
    }
}
